#include<unordered_set>
#include<vector>
using namespace std;
class Solution {
public:
    int findMaximumXOR(vector<int>& nums) {
        int res = 0;
        int mask = 0;
        for (int i = 31; i >= 0; --i) {
            mask = mask | (1 << i);
            unordered_set<int>hashSet;
            for (auto num : nums) {
                hashSet.insert(num & mask);
            }
            int tmp = res | (1 << i);
            for (auto prefix : hashSet) {
                if (hashSet.find(tmp ^ prefix) != hashSet.end()) {
                    res = tmp;
                    break;
                }
            }
        }
        return res;
    }
};